export function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg)) {
        return unescape(arr[2]);
    }
    else {
        return null;
    }
}
//设置cookie,增加到vue实例方便全局调用
export function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
};

//删除cookie
export function delCookie(name) {
    setCookie(name, "", -1); 
};

export function getScrollTop() {
    //获取滚动高度
    let scrollTop = 0;
    scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
    return scrollTop;
  };

//监听滚动条滚动到底部的事件
export function reachBottom(callback) {
    const clientHeight =
      document.documentElement.clientHeight || document.body.clientHeight;
    const scrollTop = Math.ceil(
      document.documentElement.scrollTop || document.body.scrollTop
    );
    const scrollHeight =
      document.documentElement.scrollHeight || document.body.scrollHeight;

    //滚动条滚动到底部
    if (clientHeight + scrollTop >= scrollHeight) {
      callback()
    }
  }

export function getSessionStorage(key) {
  return sessionStorage.getItem(key);
}
export function setSessionStorage(key, val) {
  return sessionStorage.setItem(key, val);
}
export function removeSessionStorage(key, val) {
  return sessionStorage.setItem(key, val);
}